{% extends "base.html" %}
{% block title %}Host List{% endblock %}
{% block content %}

<!--atsystem-->
                <!--/span-->

                <div class="span9" id="content">

                    <div class="row-fluid">
                      <!--  <div class="alert alert-success">
                                                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                            <h4>Success</h4>
                                The operation completed successfully</div>-->
                                <div class="navbar">
                                <div class="navbar-inner">
                                        <ul class="breadcrumb">
                                            <i class="icon-chevron-left hide-sidebar"><a href='#' title="Hide Sidebar" rel='tooltip'>&nbsp;</a></i>
                                            <i class="icon-chevron-right show-sidebar" style="display:none;"><a href='#' title="Show Sidebar" rel='tooltip'>&nbsp;</a></i>
                                            <li>
                                                <a href="/admin/">Dashboard</a> <span class="divider">/</span>
                                            </li>
                                            <li>
                                                <a href="/admin/hosts/">Minions</a> <span class="divider">/</span> 
                                            </li>
					<!--
                                            <li class="active">Tools</li>-->
                                        </ul>
                                </div>
                                </div>
                        </div>







                     <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Minions List</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                                                     <div class="table-toolbar">
                                      <div class="btn-group pull-left">
                                         <a href="/admin/hosts/update/"><button class="btn btn-inverse"><i class="icon-refresh icon-white"></i>Update </i></button></a>
                                      </div>
					<div class="btn-group pull-left">
										  <button class="btn btn-primary">Action</button>
										  <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle"><span class="caret"></span></button>
										  <ul class="dropdown-menu">
											<li><a href="#"  id = "action1" onclick="chk()"  value="action1">Host Status</a></li>
											<li><a href="#"  id = "action2" onclick="chk2()"  value="action2">File Copy</a></li>
											<li><a href="#"  id = "action3" onclick="chk3()"  value="action3">Exec Cmd</a></li>
											<li><a href="#"  id = "action4" onclick="chk4()"  value="action4">Install Software</a></li>
											<li><a href="#">nothing</a></li>
											<li><a href="#">nothing</a></li>
											<li class="divider"></li>
											<li><a href="#">nothing</a></li>
										  </ul>
										</div>
					 

<div class="btn-group pull-left">
                                        <label  class="help-inline"><font color="black"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;快捷功能：</b></font> </label>
                                        </div>
					<div class="btn-group pull-left" >
                                           <select id="selectfun" style="width:150px">
					      <option name=" ">Choice...</option>
                                        {% for function in functions %}
                                              <option name={{function.argname}} value="{{function.funname}}"><a id="funcomm">{{function.comment}}</a></option>
                                        {% endfor %}
                                            </select>
                                        </div>
					<div class="btn-group pull-left">
					<input  id="funarg"  />
					</div>


                                      <div class="btn-group pull-left">
                                         <a href="javascript:void(0)" onclick="chk6()" ><button class="btn btn-success">Go </button></a>
                                      </div>







                                      <div class="btn-group pull-right">
                                         <a href="javascript:vaid(0)" onclick="chk5()"><button class="btn btn-success">Add </button></a>
                                      </div>




					<div class="btn-group pull-right">
	                                   <select id="selecthost">
					{% for mgroup in mgroups %}
                                              <option><a id="mgn">{{mgroup.mg_name}}</a></option>
					{% endfor %}
                                            </select>
					</div>


					<div class="btn-group pull-right">
					<label  class="help-inline"><font color="black"><u><b>Select host add to a Group :</b></u></font> </label>
					</div>






			
                                   </div>
  
  		                  <table cellpadding="0" cellspacing="0" border="0" class="table table-bordered" id="example">
										<thead>
											<tr>
												<th><input class="uniform_on" type="checkbox" id="optionsCheckbox" value="option1"></th>
												<th>Minion ID</th>
												<th>OS Type</th>
												<th>ProductName</th>
												<th>IP Address</th>
												<th>HostName</th>
												<th>HostStatus</th>
											</tr>
										</thead>
										<tbody>
										{% for minion in minions %}
                                                                                        {% if minion.cs_stat == 'INCORRECT'%}
                                                                                        <tr bgcolor="#FF0000" class="gradeC">
                                                                                        {% else %}
                                                                                        <tr  class="gradeC">
                                                                                        {% endif %}
												<td><input name = "checkbox" class="uniform_on" type="checkbox"  value="{{minion.minion_id}}"></td>
												<td>{{minion.minion_id}}</td>
												<td>{{minion.os_type}}</td>
												<td>{{minion.productname}}</td>
												<td class="center">{{minion.ipaddr}}</td>
												<td class="center">{{minion.hostname}}</td>
												<td class="center"><a href="/admin/hosts/hresource/{{minion.minion_id}}">Status</a></td>
											</tr>
										{% endfor %}
										</tbody>
									</table>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>

       
                </div>

            </div>


<script LANGUAGE="javascript">
  $("#optionsCheckbox").click(function() {
    $("input[name='checkbox']").prop("checked", this.checked);
  });
  $("input[name='checkbox']").click(function() {
    var $subs = $("input[name='checkbox']");
    $("#optionsCheckbox").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);
  });
</script>


<script "text/javascript">
function chk(){
var obj=document.getElementsByName("checkbox");
var array1=new Array();
for(var i=0;i<obj.length;i++)
{
if(obj[i].checked)
{
array1.push(obj[i].value);
}
}

if(array1 == ""){
alert("Please choice a host least!!");
}
else{
$.post('/admin/host_exec/',
{
'arraydata':JSON.stringify(array1)
},

function(data){
alert(data);
});
}
}
///////////////////////////////////////////////////////////////////////////

function chk2(){
var obj=document.getElementsByName("checkbox");
var array2=new Array();
for(var i=0;i<obj.length;i++)
{
if(obj[i].checked)
{
array2.push(obj[i].value);
}
}
if(array2 == ""){

alert("Please choice a host least!!");
}
else
{
window.open('/admin/file_copy/?cpinfo='+array2,'newwindow','width=1100,height=800,location=no,scrollbars=yes,status=yes');
}
}

/////////////////////////////////////////////////////////////////////////////////


function chk3(){
var obj=document.getElementsByName("checkbox");
var array3=new Array();
for(var i=0;i<obj.length;i++)
{
if(obj[i].checked)
{
array3.push(obj[i].value);
}
}
if(array3 == ""){

alert("Please choice a host least!!");
}
else
{
window.open('/admin/execmd/?exeinfo='+array3,'newwindow','width=1100,height=800,location=no,scrollbars=yes,status=yes');
}
}





/////////////////////////////////////////////////////////////////////////////////


function chk4(){
var obj=document.getElementsByName("checkbox");
var array4=new Array();
for(var i=0;i<obj.length;i++)
{
if(obj[i].checked)
{
array4.push(obj[i].value);
}
}
if(array4 == ""){

alert("Please choice a host least!!");
}
else
{
window.open('/admin/software/?info='+array4,'newwindow','width=1100,height=800,location=no,scrollbars=yes,status=yes');
}
}



function chk5(){
var obj=document.getElementsByName("checkbox");
var array5=new Array();
for(var i=0;i<obj.length;i++)
{
if(obj[i].checked)
{
array5.push(obj[i].value);
}
}

var array6=new Array()
array6.push($("#selecthost option:selected").text())
array5=array5.concat(array6)

//array5=array5.push($("#gname").attr("text"))
if(array5 == ""){
alert("Please choice a host least!!");
}
else{
$.post('/admin/hosts/addtomg/',
{
'arraydata':JSON.stringify(array5)
},

function(data){
var d = dialog({
    title: '提示',
    content: data
});
d.show();

});


}
}

function chk6(){
var obj=document.getElementsByName("checkbox");
var array6=new Array();
for(var i=0;i<obj.length;i++)
{
if(obj[i].checked)
{
array6.push(obj[i].value);
}
}

var array7=new Array()
array7.push($('#selectfun').children('option:selected').val())
array7.push($("#funarg").val())

//array5=array5.push($("#gname").attr("text"))
if(array6 == ""){
alert("Please choice a host least!!");
}
else{
array6=array6.concat(array7)
$.post('/admin/hosts/shortfun/',
{
'arraydata':JSON.stringify(array6)
},

function(data){
//alert(data);
var d = dialog({
    title: '欢迎',
    content: data
});
d.show();


});
}
}







function getdata(){

alert("update new host to the minion list!!!!");
}

function window1(){
var d = dialog({
    title: '欢迎',
    content: '欢迎使用 artDialog 对话框组件！'
});
d.show();

}

$(document).ready(function(){  
 $('#selectfun').change(function(){
//   var comm=$('#selectfun').children('option:selected').val();
   var argname=$('#selectfun').find('option:selected').attr("name");
   $('#funarg').attr('value',argname);  
   })  
})


</script>













{% endblock %}
